<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title>Test validation</title>
</head>
<body>
  <form id="form1" runat="server">
    <div>
      <h3>Emulation of ASP.NET's validation</h3>

      <span id="lblName">Name: </span>
      <input name="txtName" type="text" id="txtName" />
      <span id="vldName" style="color:Red;visibility:visible">* Name is required !</span>
      <br />
    
      <span id="lblSurname">Surname: </span>
      <input name="txtSurname" type="text" id="txtSurname" />
      <span id="vldSurname" style="color:Red;visibility:visible">* Surname is required !</span>
    </div>

    <script type="text/javascript">                                                           
      function isNotEmpty(evt) {
        // evt = (evt) ? evt : ((window.event) ? event : null);
        var elem = evt.target;
        var str = elem.value;
        var re = /.+/;
        if (!str.match(re)) {
          elem.validator.style.visibility = "visible";
          return false;
        } else {
          elem.validator.style.visibility = "hidden";
          return true;
        }
      }
  
      var txtName = document.all ? document.all["txtName"] : document.getElementById("txtName");
      var vldName = document.all ? document.all["vldName"] : document.getElementById("vldName");
      txtName.validator = vldName;
      txtName.onchange = isNotEmpty;

      var txtSurname = document.all ? document.all["txtSurname"] : document.getElementById("txtSurname");
      var vldSurname = document.all ? document.all["vldSurname"] : document.getElementById("vldSurname");
      txtSurname.validator = vldSurname;
      txtSurname.onchange = isNotEmpty;
    </script>                                                                                 

  </form>
</body>
</html>
